<template>
  <div class="pagestyle">
    <list_controller
      ref="zujianname"
      v-model="state.optionsList"
      :options="state.optionsList"
      pageName=""
      @tabChange="tabChange"
      :tabName="state.tabNameData"
      :pId="route.query.primaryIndexId"
      :cid="route.query.childIndexId"
    >
      <template v-slot:opraCurdBtn1="row">
        <span>
          <el-button
            type="primary"
            style="font-size: 14px"
            link
            size="small"
            @click="lookBtn(row.row.row)"
            >查看
          </el-button>
          <el-button
            type="primary"
            style="font-size: 14px"
            link
            size="small"
            @click="editBtn(row.row.row)"
            >编辑
          </el-button>
          <el-button
            type="primary"
            style="font-size: 14px"
            link
            size="small"
            @click="deleteBtn(row.row.row)"
            >删除
          </el-button>
        </span>
      </template>
      <template v-slot:opraCurdBtnAll>
        <el-button class="btn" type="primary" link @click="addBtn('mul')">
          <el-icon>
            <CirclePlusFilled />
          </el-icon>
          <!-- <el-icon style="margin-right: 2px;">
            <svg-icon  icon-class="addtotal" />
          </el-icon> -->
          新增
        </el-button>
        <el-button class="btn" type="primary" link @click="deleteBtn('mul')">
          <el-icon> <DeleteFilled /> </el-icon>删除
        </el-button>
      </template>
    </list_controller>
    <!-- 新增弹框模拟量 -->
    <teleport to="body">
      <vxe-modal
        esc-closable
        destroy-on-close
        :lock-view="false"
        :width="660"
        :height="auto"
        v-model="state.addModal"
        resize
        :mask="true"
        @close="cancel"
      >
        <template #title>
          <div class="w100 h100 fsc mask_title">
            {{ state.modalTitle }}传感器
          </div>
        </template>
        <template #default>
          <div class="form_box">
            <el-form
              ref="formRef"
              :model="state.formData"
              :rules="state.rules"
              label-position="top"
            >
              <div v-if="state.tabName == 'simulate'">
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span
                    >传感器信息</span
                  >
                </p>
                <el-row :gutter="20">
                  <el-col :span="12">
                    <el-form-item label="传感器名称" prop="deviceName">
                      <!-- <el-select :disabled="state.editDis" clearable filterable v-model="state.formData.deviceName"
                        placeholder="请选择" @change="deviceNameChange" style="width: 100%;">
                        <el-option v-for="(item, index) in state.deviceNameList" :key="index" :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select> -->
                      <el-cascader
                        style="width: 100%"
                        clearable
                        v-model="state.formData.deviceName"
                        :options="state.deviceNameList"
                        :props="state.props"
                        @change="deviceNameChange"
                      />
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="单位" prop="">
                      <el-input
                        disabled
                        v-model="state.formData.unit"
                        placeholder="请输入"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="8">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input disabled v-model="state.formData.primaryIndexId" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.childIndexList !=null">
                    <el-form-item label="子索引" prop="childIndexId">
                      <el-select :disabled="state.editDis" clearable filterable v-model="state.formData.childIndexId"
                        placeholder="请选择" @change="childIndexChange">
                        <el-option v-for="item in state.childIndexList" :key="item.childIndexId"
                          :label="item.childIndexId+'-'+item.childIndexName" :value="item.childIndexId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col> -->

                  <el-col :span="12">
                    <el-form-item label="低量程">
                      <el-input
                        disabled
                        clearable
                        oninput="value=value.replace(/[^\d.]/g,'')"
                        v-model.number="state.formData.lowLevelUp"
                        placeholder="请输入"
                      >
                      </el-input>
                      <!-- <div class="inputrange fbc">
                        <el-input
                          disabled
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="state.formData.lowLevelUp"
                          placeholder="请输入上限"
                        >
                        </el-input>
                        <span>-</span>
                        <el-input
                          disabled
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="state.formData.lowLevelDown"
                          placeholder="请输入下限"
                        >
                        </el-input>
                      </div> -->
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="高量程">
                      <el-input
                        disabled
                        clearable
                        oninput="value=value.replace(/[^\d.]/g,'')"
                        v-model.number="state.formData.highLevelUp"
                        placeholder="请输入"
                      >
                      </el-input>
                      <!-- <div class="inputrange fbc">
                        <el-input
                          disabled
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="state.formData.highLevelUp"
                          placeholder="请输入上限"
                        >
                        </el-input>
                        <span>-</span>
                        <el-input
                          disabled
                          oninput="value=value.replace(/[^\d.]/g,'')"
                          clearable
                          v-model.number="state.formData.highLevelDown"
                          placeholder="请输入下限"
                        >
                        </el-input>
                      </div> -->
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="设备有效期">
                      <el-select
                        clearable
                        filterable
                        v-model.number="state.formData.deviceValidity"
                        placeholder="请选择"
                        style="width: 100%"
                      >
                        <el-option
                          v-for="item in state.yearList"
                          :key="item"
                          :label="item"
                          :value="item"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <!-- <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>默认报警类型</span></p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="报警模式" prop="alarmType">
                      <el-select clearable filterable v-model="state.formData.alarmType" placeholder="请选择"
                        @change="alarmTypeChange">
                        <el-option v-for="item in state.alarmmodeList" :key="item.code" :label="item.name"
                          :value="item.code">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.formData.alarmType == 1 || state.formData.alarmType == 3">
                    <el-form-item label="上限报警值≥" prop="upAlarmValue">
                      <el-input :disabled="state.nowranDis" v-model="state.formData.upAlarmValue" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.formData.alarmType == 1 || state.formData.alarmType == 3">
                    <el-form-item label="上限解报值＜" prop="upRelieveValue">
                      <el-input :disabled="state.nowranDis" v-model="state.formData.upRelieveValue" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.formData.alarmType == 2 || state.formData.alarmType == 3">
                    <el-form-item label="下限报警值≥" prop="downAlarmValue">
                      <el-input :disabled="state.noshangwranDis" v-model="state.formData.downAlarmValue"
                        placeholder="请输入"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.formData.alarmType == 2 || state.formData.alarmType == 3">
                    <el-form-item label="下限解报值＜" prop="downRelieveValue">
                      <el-input :disabled="state.noshangwranDis" v-model="state.formData.downRelieveValue"
                        placeholder="请输入"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row> -->
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span
                    >其他</span
                  >
                </p>
                <el-row :gutter="20">
                  <el-col :span="16">
                    <el-form-item label="上传图片" prop="imagePath">
                      <el-upload
                        action
                        v-model:file-list="state.fileList"
                        list-type="picture"
                        :before-upload="beforeUpload"
                        :http-request="uploadHttpRequestAdd"
                        ref="upload"
                        :on-preview="handlePictureCardPreview"
                      >
                        <el-button>
                          <el-icon> <UploadFilled /> </el-icon>上传图片
                        </el-button>
                        <template #tip>
                          <div class="el-upload__tip">
                            上传图片支持jpg/png等，大小不超过 500kb
                          </div>
                        </template>
                      </el-upload>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <div v-if="state.tabName == 'switch'">
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span
                    >传感器信息</span
                  >
                </p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="名称" prop="deviceName">
                      <!-- <el-select
                        :disabled="state.editDis"
                        clearable
                        filterable
                        v-model="state.formData.sensorName"
                        placeholder="请输入/请选择"
                        @change="sensorNameChange"
                      >
                        <el-option
                          v-for="item in state.sensorNameList"
                          :key="item.sensorName"
                          :label="item.sensorName"
                          :value="item.sensorName"
                        >
                        </el-option>
                      </el-select> -->
                      <el-cascader
                        style="width: 100%"
                        clearable
                        v-model="state.formData.deviceName"
                        :options="state.deviceNameList2"
                        :props="state.props"
                        @change="kaiguanNameChange"
                      />
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="8">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input disabled v-model="state.formData.primaryIndexId" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col> -->
                  <el-col :span="8">
                    <el-form-item label="开关量模式" prop="switchMode">
                      <el-select
                        disabled
                        clearable
                        filterable
                        v-model="state.formData.switchMode"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.switchModelList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="常态逻辑" prop="normalLogic">
                      <el-select
                        disabled
                        clearable
                        filterable
                        v-model="state.formData.normalLogic"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.normalLogicList"
                          :key="item.code"
                          :label="item.name"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="8" v-if="state.childIndexList !=null">
                    <el-form-item label="子索引" prop="childIndexId">
                      <el-select :disabled="state.editDis" clearable filterable v-model="state.formData.childIndexId"
                        placeholder="请选择" @change="childIndexChange">
                        <el-option v-for="item in state.childIndexList" :key="item.childIndexId"
                          :label="item.childIndex" :value="item.childIndexId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col> -->
                  <el-col :span="8">
                    <el-form-item label="高电平显示" prop="highLevel">
                      <el-input
                        disabled
                        clearable
                        v-model="state.formData.highLevel"
                        placeholder="请输入"
                        @blur="highShowBlur"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="低电平显示" prop="lowLevel">
                      <el-input
                        disabled
                        clearable
                        v-model="state.formData.lowLevel"
                        placeholder="请输入"
                        @blur="lowShowBlur"
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="8">
                    <el-form-item label="设备有效期">
                      <el-select clearable filterable v-model="state.formData.expiration" placeholder="请选择">
                        <el-option v-for="item in state.yearList" :key="item" :label="item" :value="item">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col> -->
                  <el-col :span="8">
                    <el-form-item label="报警类型" prop="alarmType">
                      <el-select
                        clearable
                        filterable
                        v-model="state.formData.alarmType"
                        placeholder="请选择"
                      >
                        <el-option
                          v-for="item in state.alarmmodeswitchList"
                          :key="item.code"
                          :label="item.name + '报警'"
                          :value="item.code"
                        >
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span
                    >其他</span
                  >
                </p>
                <el-row :gutter="20">
                  <el-col :span="16">
                    <el-form-item label="上传图片" prop="imagePath">
                      <el-upload
                        action
                        v-model:file-list="state.fileList1"
                        list-type="picture"
                        :before-upload="beforeUpload1"
                        :http-request="uploadHttpRequestAdd1"
                        ref="upload1"
                        :on-preview="handlePictureCardPreview"
                      >
                        <el-button>
                          <el-icon> <UploadFilled /> </el-icon>上传图片
                        </el-button>
                        <template #tip>
                          <div class="el-upload__tip">
                            上传图片支持jpg/png等，大小不超过 500kb
                          </div>
                        </template>
                      </el-upload>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <!-- <div v-if="state.tabName =='add'">
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>传感器信息</span></p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="名称" prop="sensorName">
                      <el-select :disabled="state.editDis" clearable filterable v-model="state.formData.sensorName"
                        placeholder="请选择" @change="sensorNameChange">
                        <el-option v-for="item in state.sensorNameList" :key="item.sensorName" :label="item.sensorName"
                          :value="item.sensorName">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="单位" prop="sensorUnit">
                      <el-input disabled v-model="state.formData.sensorUnit" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="主索引" prop="primaryIndexId">
                      <el-input disabled v-model="state.formData.primaryIndexId" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="累计周期" prop="resetType">
                      <el-select disabled clearable v-model="state.formData.resetType" placeholder="请选择">
                        <el-option v-for="item in state.resetTypeList" :key="item.code" :label="item.name"
                          :value="item.code">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="state.childIndexList != null">
                    <el-form-item label="子索引" prop="childIndexId">
                      <el-select :disabled="state.editDis" clearable filterable v-model="state.formData.childIndexId"
                        placeholder="请选择" @change="childIndexChange">
                        <el-option v-for="item in state.childIndexList" :key="item.childIndexId"
                          :label="item.childIndex" :value="item.childIndexId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="设备有效期">
                      <el-select clearable filterable v-model="state.formData.expiration" placeholder="请选择">
                        <el-option v-for="item in state.yearList" :key="item" :label="item" :value="item">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>累计参数</span></p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="累计模式" prop="orderType">
                      <el-select disabled clearable v-model="state.formData.orderType" placeholder="请选择">
                        <el-option v-for="item in state.orderTypeList" :key="item.code" :label="item.name"
                          :value="item.code">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="起始值" prop="startValue">
                      <el-input disabled clearable v-model="state.formData.startValue" placeholder="请输入"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="变化值" prop="changeValue">
                      <el-input disabled clearable v-model="state.formData.changeValue" placeholder="请输入"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="上限值" prop="upLimitValue">
                      <el-input disabled clearable v-model="state.formData.upLimitValue" placeholder="请输入"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="16">
                    <el-form-item label="上传图片" prop="imagePath">
                      <el-upload action v-model:file-list="state.fileList2" list-type="picture"
                        :before-upload="beforeUpload2" :http-request="uploadHttpRequestAdd2" ref="upload2"
                        :on-preview="handlePictureCardPreview">
                        <el-button>
                          <el-icon>
                            <UploadFilled />
                          </el-icon>上传图片
                        </el-button>
                        <template #tip>
                          <div class="el-upload__tip">
                            上传图片支持jpg/png等，大小不超过 500kb
                          </div>
                        </template>
                      </el-upload>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div>
              <div v-if="state.tabName =='multiple'">
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>传感器信息</span></p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-form-item label="名称" prop="sensorName">
                      <el-input clearable v-model="state.formData.sensorName" @change="multiplename" placeholder="请输入">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="设备有效期">
                      <el-select clearable filterable v-model="state.formData.expiration" placeholder="请选择">
                        <el-option v-for="item in state.yearList" :key="item" :label="item" :value="item">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>多参数信息</span></p>
                <el-row :gutter="20">
                  <el-col :span="8">
                    <el-tree-select v-model="state.nodeclickId" ref="treeRef" :data="state.getpointsensorList"
                      node-key="value" clearable placeholder="请选择" highlight-current @node-click="nodeclick" />
                  </el-col>
                  <el-col :span="1">
                    <el-button type="primary" @click="nodeclickchange">选择</el-button>
                  </el-col>
                  <el-col :span="24" style="margin-top:10px;">
                    <vxe-table height="240" :data="state.formData.sensorList" border="inner">
                      <vxe-column title="传感器名称" field="sensorName">
                      </vxe-column>
                      <vxe-column title="单位" field="sensorUnit">
                      </vxe-column>
                      <vxe-column title="主索引" field="primaryIndexId">
                      </vxe-column>
                      <vxe-column title="子索引" field="childIndex">
                      </vxe-column>
                      <vxe-column title="操作" field="show">
                        <template #default="{row,rowIndex}">
                          <el-button link type="primary" @click="sensorListdelClick(rowIndex)">
                            删除
                          </el-button>
                        </template>
                      </vxe-column>
                    </vxe-table>
                  </el-col>
                </el-row>
                <p class="mask_sub_title">
                  <svg-icon class-name="search-icon" icon-class="dot" /><span>其他</span></p>
                <el-row :gutter="20">
                  <el-col :span="16">
                    <el-form-item label="上传图片" prop="imagePath">
                      <el-upload action v-model:file-list="state.fileList3" list-type="picture"
                        :before-upload="beforeUpload3" :http-request="uploadHttpRequestAdd3" ref="upload2"
                        :on-preview="handlePictureCardPreview">
                        <el-button>
                          <el-icon>
                            <UploadFilled />
                          </el-icon>上传图片
                        </el-button>
                        <template #tip>
                          <div class="el-upload__tip">
                            上传图片支持jpg/png等，大小不超过 500kb
                          </div>
                        </template>
                      </el-upload>
                    </el-form-item>
                  </el-col>
                </el-row>
              </div> -->
            </el-form>
            <div class="form_footer">
              <el-button @click="cancel">取消</el-button>
              <el-button type="primary" @click="submitForm"> 确定 </el-button>
            </div>
          </div>
        </template>
      </vxe-modal>
    </teleport>
    <!-- 详情 -->
    <el-drawer
      v-model="state.drawerShow"
      direction="rtl"
      size="50%"
      close-on-click-modal
      :modal="true"
    >
      <template #header="{ close, titleId, titleClass }">
        <h4 class="mask_sub_title" style="color: #3e464f; margin: 0">
          <svg-icon class-name="search-icon" icon-class="dot" /><span
            >{{ state.drawerTitle }}传感器详情</span
          >
        </h4>
      </template>
      <div>
        <el-row
          :gutter="20"
          style="
            background: rgba(91, 109, 128, 0.04);
            display: flex;
            align-items: center;
            padding: 20px 0;
          "
        >
          <el-col :span="8" style="text-align: center">
            <div class="img_box">
              <img
                style="width: 120px; height: 120px"
                v-if="state.formData.address != null"
                :src="state.formData.address"
                alt=""
              />
              <img
                v-else
                style="width: 120px; height: 120px"
                src="@/assets/images/noimg.png"
              />
            </div>
            <!-- <p>{{state.formData.sensorName}}</p> -->
          </el-col>
          <el-col :span="16">
            <el-row :gutter="20">
              <el-col :span="24">
                <div v-if="state.tabName == 'simulate'">
                  <el-row :gutter="20">
                    <el-col :span="12">
                      <p>传感器名称</p>
                      <p>{{ state.formData.deviceName }}</p>
                    </el-col>
                    <el-col :span="12">
                      <p>单位</p>
                      <p>{{ state.formData.unit }}</p>
                    </el-col>
                    <!-- <el-col :span="8">
                      <p>主索引</p>
                      <p>{{state.formData.primaryIndexId}}</p>
                    </el-col> -->
                    <!-- <el-col :span="8">
                      <p>子索引</p>
                      <p>{{state.formData.childIndex}}</p>
                    </el-col> -->
                    <el-col :span="12">
                      <p>【低】量程</p>
                      <p v-if="state.formData.lowLevelUp">
                        {{ state.formData.lowLevelUp }}
                      </p>
                      <p v-else>- / -</p>
                    </el-col>
                    <el-col :span="12">
                      <p>【高】量程</p>
                      <p v-if="state.formData.highLevelUp">
                        {{ state.formData.highLevelUp }}
                      </p>
                      <p v-else>- / -</p>
                    </el-col>
                    <!-- <el-col :span="8">
                      <p>报警模式</p>
                      <p>{{state.formData.alarmTypeName}}</p>
                    </el-col> -->
                    <!-- <el-col :span="8">
                      <p>上限报警/解报值</p>
                      <p v-if="state.formData.upAlarmValue">
                        {{state.formData.upAlarmValue}}/{{state.formData.upRelieveValue}}</p>
                      <p v-else>- / -</p>
                    </el-col> -->
                    <!-- <el-col :span="8">
                      <p>下限报警/解报值</p>
                      <p v-if="state.formData.downAlarmValue">
                        {{state.formData.downAlarmValue}}/{{state.formData.downRelieveValue}}</p>
                      <p v-else>- / -</p>
                    </el-col> -->
                    <!-- <el-col :span="8">
                      <p>设备有效期</p>
                      <p>{{state.formData.expiration}}</p>
                    </el-col> -->
                  </el-row>
                </div>
                <div v-if="state.tabName == 'switch'">
                  <el-row :gutter="20">
                    <el-col :span="8">
                      <p>名称</p>
                      <p>{{ state.formData.deviceName }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>主索引</p>
                      <p>{{ state.formData.specificSwitchId }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>开关量模式</p>
                      <p>{{ state.formData.switchMode }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>子索引</p>
                      <p>{{ state.formData.specificSwitchSubId }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>高电平显示</p>
                      <p>{{ state.formData.highLevel }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>低电平显示</p>
                      <p>{{ state.formData.lowLevel }}</p>
                    </el-col>
                    <el-col :span="8">
                      <p>常态逻辑</p>
                      <p>{{ state.formData.normalLogic }}</p>
                    </el-col>
                    <!-- <el-col :span="8">
                      <p>设备有效期</p>
                      <p>{{state.formData.expiration}}</p>
                    </el-col> -->
                    <el-col :span="8">
                      <p>报警类型</p>
                      <p>{{ state.formData.alarmType + "报警" }}</p>
                    </el-col>
                  </el-row>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <p
          v-if="state.tabNameData == '模拟量传感器'"
          class="drawer_sub_title"
          style="margin: 20px 0 12px 0"
        >
          <span class="sub_title_line">引用测点</span>
        </p>
        <el-row
          v-if="state.tabNameData == '模拟量传感器'"
          :gutter="20"
          style="
            background: rgba(91, 109, 128, 0.04);
            display: flex;
            align-items: center;
            padding: 10px 0;
            margin-top: 10px;
          "
        >
          <el-col :span="24">
            <div class="fsc" style="margin-bottom: 10px">
              <span
                class="wn"
                style="
                  font-size: 14px;
                  font-weight: 700;
                  color: rgb(51, 51, 51);
                  margin-right: 10px;
                "
                >编号</span
              >
              <el-input
                style="width: 200px; margin-right: 10px"
                v-model="state.pointId"
                placeholder="请输入"
                clearable
              >
              </el-input>
              <el-button @click="btnclick(1)" size="default" type="primary"
                >查询</el-button
              >
              <el-button
                @click="btnclick(2)"
                size="default"
                style="background-color: #f2f4f5; border: none"
                >重置
              </el-button>
            </div>
            <vxe-table
              height="240"
              :data="state.pontList"
              :row-style="rowStyle"
            >
              <vxe-column title="序号" type="seq" :width="55"></vxe-column>
              <!-- <vxe-column
                v-for="(item, index) in state.ponittableheads"
                :field="item.field"
                :title="item.title"
                :params="{ name: item.name }"
                :width="item.width ? item.width : ''"
                :key="index"
              ></vxe-column> -->
              <vxe-column
                field="pointNum"
                title="编号"
                show-overflow
                tooltip-effect="dark"
              ></vxe-column>
              <vxe-column
                field="sensorPlace"
                title="地点"
                show-overflow
                tooltip-effect="dark"
              ></vxe-column>
              <vxe-column title="操作">
                <template #default="{ row }">
                  <el-button link type="primary" @click="tobtnClick(row)"
                    >查看测点详情</el-button
                  >
                </template>
              </vxe-column>
            </vxe-table>
            <div style="margin-top: 10px; display: flex; justify-content: end">
              <el-pagination
                class="pages globalFontSize"
                v-model:current-page="state.page.currentPage"
                v-model:page-size="state.page.pageSize"
                :page-sizes="[10, 20, 30, 40]"
                background
                layout="total, sizes, prev, pager, next, jumper"
                :total="state.page.total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </el-col>
        </el-row>
      </div>
      <!-- <template #footer>
        <div style="flex: auto">
          <el-button @click="cancelClick">取消</el-button>
          <el-button type="primary" @click="confirmClick(state.formData)"
            >编辑</el-button
          >
        </div>
      </template> -->
    </el-drawer>
    <el-dialog v-model="state.dialogVisiblepictureCardPreview">
      <img :src="state.dialogImageUrl" alt="Preview Image" />
    </el-dialog>
  </div>
</template>
<script setup>
import list_controller from "@/components/commonCom/list_controller";
import { computed, reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { table_headers } from "@/components/commonCom/table_headers";
import axios from "@/utils/request";
import {
  getchildIndex,
  getsensorName,
  getunit,
  fileupload,
  getchildIndexadd,
  getsensorNameadd,
  getpointsensor,
  validParamData,
} from "@/api/config";
import usePagesStore from "@/store/modules/pages";
import { create } from "lodash";
const { proxy } = getCurrentInstance();
const store = usePagesStore();
const router = useRouter();
const route = useRoute();
const upload = ref();
const upload1 = ref();
const upload2 = ref();
components: {
  list_controller;
}
let previewHttps = import.meta.env.VITE_APP_HTTP;
let modeHttps = import.meta.env.MODE;
const optionsList = ref({});
let state = reactive({
  page: {
    currentPage: 1,
    pageSize: 10,
    total: 0,
  },
  num: 0,
  editDis: false,
  nowranDis: false,
  noshangwranDis: false,
  tabNameData: "模拟量传感器",
  optionsList: {},
  options: {
    isShowCaozuo: true,
    tabList: [
      {
        tabIndex: 1,
        name: "模拟量传感器",
      },
      {
        tabIndex: 2,
        name: "开关量传感器",
      },
    ],
    tableheads: computed(() => table_headers.gasBaseImitateSensor),
    queryList: {
      dropdownUrl: "",
      querys: [
        {
          field: "deviceName",
          title: "传感器名称",
          type: "input",
          binddata: "",
        },
        {
          field: "primaryIndex",
          title: "主索引",
          type: "select",
          binddata: "",
          options: [],
        },
        {
          field: "subIndex",
          title: "子索引",
          type: "select",
          binddata: "",
          options: [],
        },
      ],
      queryMap: new Map([
        ["sensorTypeId", "safety_pointType"],
        ["deviceTypeId", "safety_deviceType"],
        ["alarmTypeId", "alarmType"],
      ]),
    },
    dataUrl: "/imitate/sensor/list",
    delUrl: "/imitate/sensor/",
    addUrl: "/imitate/sensor/add",
    // descUrl: '/sensor/simulate/detail?id=',
    editUrl: "/imitate/sensor/update",
  },
  options1: {
    isShowCaozuo: true,
    tabList: [
      {
        tabIndex: 1,
        name: "模拟量传感器",
      },
      {
        tabIndex: 2,
        name: "开关量传感器",
      },
    ],
    tableheads: computed(() => table_headers.gasBaseSwitchSensor),
    queryList: {
      dropdownUrl: "",
      querys: [
        {
          field: "deviceName",
          title: "传感器名称",
          type: "input",
          binddata: "",
        },
        {
          field: "primaryIndex",
          title: "主索引",
          type: "select",
          binddata: "",
          options: [],
        },
        {
          field: "subIndex",
          title: "子索引",
          type: "select",
          binddata: "",
          options: [],
        },
      ],
      queryMap: new Map([
        ["sensorTypeId", "safety_pointType"],
        ["deviceTypeId", "safety_deviceType"],
        ["alarmTypeId", "alarmType"],
      ]),
    },
    dataUrl: "/switch/sensor/list",
    delUrl: "/switch/sensor/",
    addUrl: "/switch/sensor/add",
    // descUrl: '/sensor/switch/detail?id=',
    editUrl: "/switch/sensor/update",
  },
  // 表单
  tabName: "simulate",
  addModal: false,
  drawerShow: false,
  drawerTitle: "模拟量",
  modalTitle: "新增模拟传感器",
  formRef: null,
  formData: {
    sensorName: "",
  },
  rules: {
    deviceName: [
      {
        required: true,
        message: "请选择传感器名称",
        trigger: "change",
      },
    ],
    // sensorUnit: [
    //   {
    //     required: true,
    //     message: "请选择单位",
    //     trigger: "change",
    //   },
    // ],
    childIndexId: [
      {
        required: true,
        message: "请选择子索引",
        trigger: "change",
      },
    ],
    switchModel: [
      {
        required: true,
        message: "请选择开关量模式",
        trigger: "change",
      },
    ],
    normalLogic: [
      {
        required: true,
        message: "请选择常态逻辑",
        trigger: "change",
      },
    ],
    highShow: [
      {
        required: true,
        message: "请输入高电平名称",
        trigger: "blur",
      },
    ],
    lowShow: [
      {
        required: true,
        message: "请输入低电平名称",
        trigger: "blur",
      },
    ],
    alarmType: [
      {
        required: true,
        message: "请选择报警类型",
        trigger: "change",
      },
    ],
    resetType: [
      {
        required: true,
        message: "请选择累计周期",
        trigger: "change",
      },
    ],
    orderType: [
      {
        required: true,
        message: "请选择累计模式",
        trigger: "change",
      },
    ],
    sensorUnit: [
      {
        required: true,
        message: "请选择单位",
        trigger: "change",
      },
    ],
    startValue: [
      {
        required: true,
        message: "请输入起始值",
        trigger: "blur",
      },
    ],
    changeValue: [
      {
        required: true,
        message: "请输入变化值",
        trigger: "blur",
      },
    ],
    upLimitValue: [
      {
        required: true,
        message: "请输入上限值",
        trigger: "blur",
      },
    ],
  },
  editId: undefined,
  // 下拉数据
  childIndexList: null, //索引
  sensorNameList: [], //传感器
  deviceNameList: [], //模拟量传感器名称下拉内容
  deviceNameList2: [], //开关量传感器名称下拉内容
  props: {
    value: "value",
    label: "label",
    children: "childs",
  },
  unitList: [], //单位
  alarmmodeList: [
    {
      code: 0,
      name: "无报警",
    },
    {
      code: 1,
      name: "上限报警",
    },
    {
      code: 2,
      name: "下限报警",
    },
    {
      code: 3,
      name: "上下限报警",
    },
  ], //报警模式-模拟量
  alarmmodeswitchList: [
    {
      // code: 0,
      code: "无",
      name: "无",
    },
    {
      // code: 1,
      code: "高电平",
      name: "高电平",
    },
    {
      // code: 2,
      code: "低电平",
      name: "低电平",
    },
  ], //报警模式-开关量
  normalLogicList: [
    {
      // code: 0,
      code: "低电平",
      name: "低电平",
    },
    {
      // code: 1,
      code: "高电平",
      name: "高电平",
    },
  ],
  switchModelList: [
    {
      // code: 0,
      code: "二态",
      name: "二态",
    },
    {
      // code: 1,
      code: "三态",
      name: "三态",
    },
  ],
  resetTypeList: [
    {
      code: 0,
      name: "个数",
    },
    {
      code: 1,
      name: "小时",
    },
    {
      code: 2,
      name: "班",
    },
    {
      code: 3,
      name: "天",
    },
    {
      code: 4,
      name: "月",
    },
    {
      code: 5,
      name: "年",
    },
  ],
  orderTypeList: [
    {
      code: 0,
      name: "递增",
    },
    {
      code: 1,
      name: "递减",
    },
  ],
  yearList: [
    "1年",
    "2年",
    "3年",
    "4年",
    "5年",
    "6年",
    "7年",
    "8年",
    "9年",
    "10年",
  ],
  detailBtn: true,
  pontList: [],
  ponittableheads: computed(() => table_headers.sensorRefPoint),
  pointId: "",
  pointsensorId: "",
  nodeclickList: undefined,
  getpointsensorList: [],
  nodeclickId: undefined,
  childIndexId: undefined,
  normalLogic: undefined,
  fileList: [],
  fileList1: [],
  fileList2: [],
  fileList3: [],
  dialogVisiblepictureCardPreview: false,
  dialogImageUrl: "",
});
// 查看按钮
function lookBtn(row) {
  console.log(row, "rowrow");
  state.drawerShow = true;
  state.detailBtn = false;
  state.formData = row;
  let imagePath = imgStr(row.address);
  let imageName = LastStr(row.address);
  state.formData.address = imagePath;
  console.log(state.formData, "state.formData");
  let descUrltype = state.options.descUrl;
  if (state.tabName == "simulate") {
    descUrltype = state.options.descUrl;
    state.drawerTitle = "模拟量";
    getpointList(3, row.id);
    // axios
    //   .post("/imitate/sensor/queryPointBySensorId", {
    //     imitateSensorId: row.id,
    //   })
    //   .then((res) => {
    //     if (res.rows) {
    //       state.pontList = res.rows;
    //     }
    //   });
    // state.pointsensorId = "A" + row.id;
    // getpointList(row.pointId, "A" + row.id);
  } else if (state.tabName == "switch") {
    descUrltype = state.options1.descUrl;
    state.drawerTitle = "开关量";
    // state.pointsensorId = "D" + row.id;
    // getpointList(row.pointId, "D" + row.id);
  }
  // axios.get(descUrltype + row.id).then((res) => {
  //   if (res.code == 200) {
  //     state.formData = res.data;
  //   }
  // });
}
const handleSizeChange = (val) => {
  console.log(`每页 ${val} 条`);
  state.page.pageSize = val;
  if (state.pointId) {
    //有搜索项
    getpointList(1, state.pointId);
  } else {
    getpointList(3, state.formData.id);
  }
};
const handleCurrentChange = (val) => {
  console.log(`当前页: ${val}`);
  state.page.currentPage = val;
  getpointList();
};
// 引用测点查询
function btnclick(type) {
  if (type == 1) {
    getpointList(type, state.pointId);
  } else {
    state.pointId = "";
    getpointList(type, state.formData.id);
  }
}

function tobtnClick(row) {
  console.log(row, "rowrow");
  router.push({
    path: "/jcpz/fzjcd",
    query: {
      id: row.id,
    },
  });
}
// 引用测点查询
function getpointList(type, id) {
  let obj = {
    imitateSensorId: id,
  };
  if (type == 1) {
    obj = {
      pointNum: id,
      imitateSensorId: state.formData.id,
      pageNum: state.page.currentPage,
      pageSize: state.page.pageSize,
    };
  } else {
    obj = {
      imitateSensorId: id,
      pageNum: state.page.currentPage,
      pageSize: state.page.pageSize,
    };
  }
  axios.post("/imitate/sensor/queryPointBySensorId", obj).then((res) => {
    if (res.rows) {
      state.pontList = res.rows;
      state.page.total = res.total;
    }
  });
}
// 新增按钮
function addBtn(row) {
  state.addModal = true;
  state.formData = {};
  state.editId = undefined;
  state.editDis = false;
  state.childIndexList = null;
  state.fileList = [];
  state.fileList1 = [];
  state.fileList2 = [];
  state.fileList3 = [];
  if (state.tabName == "simulate") {
    state.modalTitle = "新增模拟量";
    // getSelectList(state.tabName)
  } else if (state.tabName == "switch") {
    state.modalTitle = "新增开关量";
    // getSelectList(state.tabName)
  }
  //  else if (state.tabName == 'add') {
  //   state.modalTitle = '新增累计量'
  //   getSelectList(state.tabName)

  // } else {
  //   state.modalTitle = '新增多参量'
  //   getgetpointsensorData()
  // }
}

function imgStr(str) {
  if (str) {
    let index = str.search("profile");
    str = str.substring(index, str.length);
    let value =
      modeHttps == "development"
        ? "/dev-api/"
        : modeHttps == "production"
        ? "/prod-api/"
        : "/stage-api/";
    let urlImage = previewHttps + value + str;
    console.log(urlImage, "urlImage");
    return urlImage;
  }
}
function LastStr(str) {
  if (str) {
    let index = str.lastIndexOf("/");
    str = str.substring(index + 1, str.length);
    console.log(str, "strstr");
    return str;
  }
}

// 编辑按钮
function editBtn(row) {
  console.log(row, "rowrow");
  let imagePath = imgStr(row.address);
  let imageName = LastStr(row.address);
  state.formData = row;
  state.addModal = true;
  state.detailBtn = true;
  state.editDis = true;
  state.editId = row.id;
  state.childIndexList = [];
  let descUrltype = state.options.descUrl;
  if (state.tabName == "simulate") {
    state.fileList = [];
    state.fileList.push({
      name: imageName,
      url: imagePath,
    });
    state.formData.deviceName = [
      row.specificImitateId,
      row.specificImitateSubId,
    ];
    descUrltype = state.options.descUrl;
    state.modalTitle = "编辑模拟量";
  } else if (state.tabName == "switch") {
    state.fileList1 = [];
    state.fileList1.push({
      name: imageName,
      url: imagePath,
    });
    state.formData.deviceName = [row.specificSwitchId, row.specificSwitchSubId];

    descUrltype = state.options1.descUrl;
    state.modalTitle = "编辑开关量";
    console.log(state.formData, "state.formData");
  }
  // state.childIndexId = row.childIndexId;
  // state.normalLogic = row.normalLogic;
  // axios.get(descUrltype + row.id).then((res) => {
  //   if (res.code == 200) {
  //     state.formData = res.data;
  //     state.fileList = [
  //       {
  //         name: LastStr(state.formData.imagePath),
  //         url: state.formData.imagePath,
  //       },
  //     ];
  //     state.fileList1 = [
  //       {
  //         name: LastStr(state.formData.imagePath),
  //         url: state.formData.imagePath,
  //       },
  //     ];
  //     state.fileList2 = [
  //       {
  //         name: LastStr(state.formData.imagePath),
  //         url: state.formData.imagePath,
  //       },
  //     ];
  //     state.fileList3 = [
  //       {
  //         name: LastStr(state.formData.imagePath),
  //         url: state.formData.imagePath,
  //       },
  //     ];
  //     state.formData.childIndexId = res.data.childIndex;
  //     state.editId = res.data.id;
  //     state.editDis = true;
  //     if (state.tabName == "switch") {
  //       state.alarmmodeswitchList = [
  //         {
  //           code: 0,
  //           name: "无",
  //         },
  //         {
  //           code: 1,
  //           name: state.formData.highShow,
  //         },
  //         {
  //           code: 2,
  //           name: state.formData.lowShow,
  //         },
  //       ];
  //     }
  //   }
  // });
}
function deleteBtn(row) {
  let delUrltype = state.options.delUrl;
  if (state.tabName == "simulate") {
    delUrltype = state.options.delUrl;
  } else if (state.tabName == "switch") {
    delUrltype = state.options1.delUrl;
  }
  let ids = [];
  if (row != "mul") {
    ids = [row.id];
  } else {
    if (store.records.length > 0) {
      ids = store.records.map((item) => {
        return item.id;
      });
    } else {
      proxy.$modal.msgSuccess("请先勾选所要删除数据!");
    }
  }
  if (ids.length > 0) {
    ElMessageBox.confirm("确定要删除吗?", "温馨提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        axios.delete(delUrltype + ids).then((res) => {
          if (res.code == 200) {
            proxy.$refs["zujianname"].getData();
            state.addModal = false;
            proxy.$modal.msgSuccess(res.msg);
            store.records = [];
          }
        });
      })
      .catch(() => {
        proxy.$modal.msgWarning("删除取消");
      });
  }
}
// 取消抽屉
function cancelClick() {
  state.drawerShow = false;
}
// 编辑抽屉
function confirmClick(row) {
  state.drawerShow = false;
  state.addModal = true;
  state.detailBtn = true;
  state.editDis = true;
  state.childIndexList = [];
  let descUrltype = state.options.descUrl;
  if (state.tabName == "simulate") {
    descUrltype = state.options.descUrl;
    state.modalTitle = "编辑模拟量";
  } else if (state.tabName == "switch") {
    descUrltype = state.options1.descUrl;
    state.modalTitle = "编辑开关量";
    // state.alarmmodeswitchList = [{
    //   code: 0,
    //   name: '无'
    // }, {
    //   code: 1,
    //   name: '开'
    // }, {
    //   code: 2,
    //   name: '停'
    // }]
  } else if (state.tabName == "add") {
    descUrltype = state.options2.descUrl;
    state.modalTitle = "编辑累计量";
  } else {
    descUrltype = state.options3.descUrl;
    state.modalTitle = "编辑多参量";
    state.nodeclickId = undefined;
    getgetpointsensorData();
  }
  state.childIndexId = row.childIndexId;
  axios.get(descUrltype + row.id).then((res) => {
    if (res.code == 200) {
      state.formData = res.data;
      state.formData.childIndexId = res.data.childIndex;
      state.editId = res.data.id;
      state.editDis = true;
      if (state.tabName == "switch") {
        state.alarmmodeswitchList = [
          {
            code: 0,
            name: "无",
          },
          {
            code: 1,
            name: state.formData.highShow,
          },
          {
            code: 2,
            name: state.formData.lowShow,
          },
        ];
      }
    }
  });
}
/** 提交按钮 */
function submitForm() {
  let addUrltype = state.options.addUrl;
  let editUrltype = state.options.editUrl;
  if (state.tabName == "simulate") {
    addUrltype = state.options.addUrl;
    editUrltype = state.options.editUrl;
  } else if (state.tabName == "switch") {
    addUrltype = state.options1.addUrl;
    editUrltype = state.options1.editUrl;
  }
  proxy.$refs["formRef"].validate((valid) => {
    if (valid) {
      delete state.formData.deviceName;
      // console.log(state.childIndexId, "state.childIndexId");
      // state.formData.childIndexId = state.childIndexId;
      // state.formData.normalLogic = state.normalLogic;
      state.formData.highLevelDown = 0; //高量程下限
      state.formData.lowLevelDown = 0; //低量程下限
      if (state.editId) {
        state.formData.id = state.editId;
        axios.post(editUrltype, state.formData).then((res) => {
          if (res.code == 200) {
            proxy.$refs["zujianname"].getData();
            state.addModal = false;
            proxy.$modal.msgSuccess(res.msg);
          }
        });
      } else {
        axios.post(addUrltype, state.formData).then((res) => {
          if (res.code == 200) {
            proxy.$refs["zujianname"].getData();
            state.addModal = false;
            proxy.$modal.msgSuccess(res.msg);
            state.fileList = [];
          }
        });
      }
    }
  });
}

function cancel() {
  proxy.$refs["zujianname"].getData();
  state.addModal = false;
}

function multiplename(val) {
  axios
    .get("/sensor/multiple/validParam", {
      params: {
        type: 0,
        value: val,
        id: state.editId,
      },
    })
    .then((res) => {
      if (res.code == 200) {
      }
    });
}
tabChange("模拟量传感器");
function tabChange(val) {
  state.formData = {};
  state.tabNameData = val;
  if (val == "模拟量传感器") {
    let moniArr = [];
    let moniArr2 = [];
    state.optionsList = state.options;
    // setTimeout(() => {
    //   proxy.$refs['zujianname'].getData()
    // }, 200);
    // getSelectList('simulate')
    state.tabName = "simulate";
    // state.formData.alarmType = state.alarmmodeList[0].code
    // axios
    //   .post(state.optionsList.dataUrl, {
    //     pageNum: 1,
    //     pageSize: 1000,
    //   })
    //   .then((res) => {
    //     if (res.rows) {
    //       moniArr = res.rows.map((item) => {
    //         return { label: item.primaryIndex, value: item.primaryIndex };
    //       });
    //       state.options.queryList.querys[1].options=moniArr
    //       moniArr2 = res.rows.map((item) => {
    //         return { label: item.subIndex, value: item.subIndex };
    //       });
    //       state.options.queryList.querys[2].options=moniArr2
    //       console.log(state.options.queryList.querys[1].options, "options1");
    //       console.log(state.options.queryList.querys[2].options, "options2");
    //     }
    //   });
  } else if (val == "开关量传感器") {
    state.optionsList = state.options1;
    // setTimeout(() => {
    //   proxy.$refs['zujianname'].getData()
    // }, 200);
    // getSelectList('switch')
    state.tabName = "switch";
    state.formData.alarmType = state.alarmmodeswitchList[0].code;
    //  axios.post(state.optionsList.dataUrl, {
    //    pageNum: 1,
    //    pageSize: 1000,
    //  }
    //  ).then((res) => {
    //    if (res.rows) {
    //      state.options1.queryList.querys[1].options = res.rows.map((item) => {
    //        return { label: item.primaryIndex, value: item.primaryIndex };
    //      });
    //      state.options1.queryList.querys[2].options = res.rows.map((item) => {
    //        return { label: item.subIndex, value: item.subIndex };
    //      });
    //    }
    //  });
  }
  setTimeout(() => {
    getSelectList();
    proxy.$refs["zujianname"].getData();
  }, 200);
}
// state.optionsList = state.options;
// 获取多参新增下拉
function getgetpointsensorData() {
  let arr = [];
  getpointsensor().then((res) => {
    if (res.data.length > 0) {
      res.data.forEach((item) => {
        item.label = item.name;
        item.value = item.name;
        item.sensors.forEach((item1) => {
          item1.label = item1.sensorName;
          item1.value = item1.primaryIndexId;
          let child = item1.childIndexList.map((item2) => {
            item2.label = item2.childIndex;
            item2.value = item2.childIndex;
            return item2;
          });
          item1.children = child;
        });
        item.children = item.sensors;
      });
      arr = res.data;
      state.getpointsensorList = arr;
    }
  });
}

function getSelectList(val) {
  // getsensorName(val).then(res => {
  //   state.sensorNameList = res.data
  // })
  let arr = [];
  let childs = [];
  //开关量
  let arr2 = [];
  let childs2 = [];
  if (state.tabNameData == "模拟量传感器") {
    axios.post("/gas/imitate/list", {}).then((res) => {
      if (res.rows) {
        // state.deviceNameList = res.rows.map(item => { return { label: item.name, value: item.id } })
        res.rows.forEach((item, index) => {
          arr.push({
            label: item.deviceName + "-" + item.primaryIndex,
            value: item.id,
            name: item.deviceName,
            childs: [],
          });
          if (item.gasBaseExFactorySpecificImitateSubIndexList) {
            childs = [];
            item.gasBaseExFactorySpecificImitateSubIndexList.forEach(
              (item1, index1) => {
                childs.push({
                  label: item1.number + "-" + item1.subIndexName,
                  value: item1.id,
                  items: item1,
                  name: item1.subIndexName,
                  // id: item1.id,
                });
              }
            );
            arr[index].childs = childs;
          }
        });
        state.deviceNameList = arr;
      }
    });
  } else if (state.tabNameData == "开关量传感器") {
    axios.post("/gas/switch/list", {}).then((res) => {
      if (res.rows) {
        // state.deviceNameList = res.rows.map(item => { return { label: item.name, value: item.id } })
        res.rows.forEach((item, index) => {
          arr2.push({
            label: item.deviceName + "-" + item.primaryIndex,
            value: item.id,
            name: item.deviceName,
            childs: [],
          });
          if (item.specificSwitchSubIndexList) {
            childs2 = [];
            item.specificSwitchSubIndexList.forEach((item1, index1) => {
              childs2.push({
                label: item1.number + "-" + item1.subIndexName,
                value: item1.id,
                items: item1,
                name: item1.subIndexName,
                // id: item1.id,
              });
            });
            arr2[index].childs = childs2;
          }
        });
        state.deviceNameList2 = arr2;
      }
    });
  }
  let moniArr = [];
  let moniArr2 = [];
  let kaiguanArr = [];
  let kaiguanArr2 = [];
  axios
    .post(state.optionsList.dataUrl, {
      pageNum: 1,
      pageSize: 999,
    })
    .then((res) => {
      if (res.rows) {
        if (state.tabNameData == "模拟量传感器") {
          moniArr = res.rows.map((item) => {
            return { label: item.primaryIndex, value: item.primaryIndex };
          });
          moniArr = [...new Set(moniArr.map((t) => JSON.stringify(t)))].map(
            (s) => JSON.parse(s)
          );
          state.options.queryList.querys[1].options = moniArr;
          moniArr2 = res.rows.map((item) => {
            return { label: item.subIndex, value: item.subIndex };
          });
          moniArr2 = [...new Set(moniArr2.map((t) => JSON.stringify(t)))].map(
            (s) => JSON.parse(s)
          );
          state.options.queryList.querys[2].options = moniArr2;
        } else if (state.tabNameData == "开关量传感器") {
          kaiguanArr = res.rows.map((item) => {
            return { label: item.primaryIndex, value: item.primaryIndex };
          });
          kaiguanArr = [
            ...new Set(kaiguanArr.map((t) => JSON.stringify(t))),
          ].map((s) => JSON.parse(s));
          state.options1.queryList.querys[1].options = kaiguanArr;
          kaiguanArr2 = res.rows.map((item) => {
            return { label: item.subIndex, value: item.subIndex };
          });
          kaiguanArr2 = [
            ...new Set(kaiguanArr2.map((t) => JSON.stringify(t))),
          ].map((s) => JSON.parse(s));
          state.options1.queryList.querys[2].options = kaiguanArr2;
        }
      }
    });
}

// getSelectList("simulate");
//模拟量传感器名称下拉事件
function deviceNameChange(val) {
  console.log(val, "val");
  console.log(state.deviceNameList, "state.deviceNameList");
  state.formData.specificImitateId = val[0]; //模拟量主键id
  state.formData.specificImitateSubId = val[1]; //模拟量子主键id
  state.formData.unit = ""; //子索引单位
  state.formData.highLevelUp = ""; //高量程上限
  state.formData.highLevelDown = ""; //高量程下限
  state.formData.lowLevelUp = ""; //低量程上限
  state.formData.lowLevelDown = ""; //低量程下限
  state.deviceNameList.forEach((item) => {
    if (item.value == val[0]) {
      item.childs.forEach((item1) => {
        if (item1.value == val[1]) {
          state.formData.unit = item1.items.subIndexUnit; //子索引单位
          state.formData.highLevelUp = item1.items.highRangeUp; //高量程上限
          state.formData.highLevelDown = item1.items.highRangeDown; //高量程下限
          state.formData.lowLevelUp = item1.items.lowRangeUp; //低量程上限
          state.formData.lowLevelDown = item1.items.lowRangeDown; //低量程下限
        }
      });
    }
  });
}
//开关量传感器名称下拉事件
function kaiguanNameChange(val) {
  console.log(val, "val");
  console.log(state.deviceNameList2, "state.deviceNameList");
  state.formData.specificSwitchId = val[0]; //模拟量主键id
  state.formData.specificSwitchSubId = val[1]; //模拟量子主键id
  state.formData.switchMode = ""; //开关量模式
  state.formData.normalLogic = ""; //常态逻辑
  state.formData.highLevel = ""; //高电平显示
  state.formData.lowLevel = ""; //低电平显示
  state.deviceNameList2.forEach((item) => {
    if (item.value == val[0]) {
      item.childs.forEach((item1) => {
        if (item1.value == val[1]) {
          state.formData.switchMode = item1.items.switchMode; //开关量模式
          state.formData.normalLogic = item1.items.normalLogic; //常态逻辑
          state.formData.highLevel = item1.items.highLevel; //高电平显示
          state.formData.lowLevel = item1.items.lowLevel; //低电平显示
        }
      });
    }
  });
}
function sensorNameChange(val) {
  state.sensorNameList.forEach((item) => {
    // if (item.sensorName == val) {
    //   state.formData.sensorUnit = item.sensorUnit
    //   state.formData.primaryIndexId = item.primaryIndexId
    //   if (state.tabName == 'simulate') {
    //     state.childIndexList = item.sensorSimulateChildList
    //     if (item.sensorSimulateChildList == null) {
    //       state.formData.highScaleDown = item.highScaleDown
    //       state.formData.highScaleUp = item.highScaleUp
    //       state.formData.lowScaleDown = item.lowScaleDown
    //       state.formData.lowScaleUp = item.lowScaleUp
    //     } else {
    //       state.formData.highScaleDown = undefined
    //       state.formData.highScaleUp = undefined
    //       state.formData.lowScaleDown = undefined
    //       state.formData.lowScaleUp = undefined
    //     }
    //   } else if (state.tabName == 'switch') {
    //     state.childIndexList = item.sensorSwitchChildList
    //     if (item.sensorSwitchChildList == null) {
    //       state.formData.switchModel = item.switchModel
    //       state.formData.highShow = item.highShow
    //       state.formData.lowShow = item.lowShow
    //       state.normalLogic = item.normalLogic
    //       state.formData.normalLogic = item.normalLogicName
    //       // state.alarmmodeswitchList=[{code:0,name:'无'},{code:1,name:'开'},{code:2,name:'停'}]
    //       state.alarmmodeswitchList = [{
    //         code: 0,
    //         name: '无'
    //       }, {
    //         code: 1,
    //         name: item.highShow
    //       }, {
    //         code: 2,
    //         name: item.lowShow
    //       }]
    //     } else {
    //       state.formData.highShow = undefined
    //       state.formData.lowShow = undefined
    //       state.formData.normalLogic = undefined
    //     }
    //   } else if (state.tabName == 'add') {
    //     state.childIndexList = item.sensorAddChildList
    //     state.formData.resetType = item.resetType
    //     if (item.sensorAddChildList == null) {
    //       state.formData.orderType = item.orderType
    //       state.formData.startValue = item.startValue
    //       state.formData.changeValue = item.changeValue
    //       state.formData.upLimitValue = item.upLimitValue
    //       state.formData.upLimitValue = item.upLimitValue
    //     } else {}
    //   }
    // }
  });
}
//传感器子索引下拉事件
function childIndexChange(val) {
  state.childIndexList.forEach((item) => {
    if (item.childIndexId == val) {
      state.formData.childIndexName = item.childIndexName;
      state.formData.highScaleDown = item.highScaleDown;
      state.formData.highScaleUp = item.highScaleUp;
      state.formData.lowScaleDown = item.lowScaleDown;
      state.formData.lowScaleUp = item.lowScaleUp;
      state.formData.sensorUnit = item.sensorUnit;
      // 开关量
      state.formData.switchModel = item.switchModel;
      state.formData.highShow = item.highShow;
      state.formData.lowShow = item.lowShow;
      state.formData.normalLogic = item.normalLogicName;
      state.alarmmodeswitchList = [
        {
          code: 0,
          name: "无",
        },
        {
          code: 1,
          name: item.highShow,
        },
        {
          code: 2,
          name: item.lowShow,
        },
      ];
      // state.alarmmodeswitchList=[{code:0,name:'无'},{code:1,name:'开'},{code:2,name:'停'}]
      // 累计量
      state.formData.orderType = item.orderType;
      state.formData.startValue = item.startValue;
      state.formData.changeValue = item.changeValue;
      state.formData.upLimitValue = item.upLimitValue;
      state.formData.upLimitValue = item.upLimitValue;
    }
  });
}
const fileType = ["jpg", "png", "gif", "jpg", "jpeg"]; // 允许的文件类型
const uploadHttpRequestAdd = (data) => {
  upload.value.clearFiles();
  const formData = new FormData();
  formData.append("file", data.file);
  fileupload(formData).then((res) => {
    console.log(modeHttps, "modeHttps");
    let value =
      modeHttps == "development"
        ? "/dev-api"
        : modeHttps == "production"
        ? "/prod-api"
        : "/stage-api";
    state.formData.address = previewHttps + value + res.fileName;
    state.formData.originalFilename = res.originalFilename;
    state.fileList = [];
    state.fileList.push({
      name: res.originalFilename,
      url: state.formData.address,
    });
    console.log(state.fileList, "state.fileList");
    proxy.$modal.msgSuccess(res.msg);
  });
};
//模拟量上传文件
const beforeUpload = (file) => {
  //上传前的钩子
  if (file.type != "" || file.type != null || file.type != undefined) {
    //截取文件的后缀，判断文件类型
    const FileExt = file.name.replace(/.+\./, "").toLowerCase();
    // 计算文件的大小
    const isLt5M = file.size / 1024 < 500; //这里做文件大小限制
    //如果大于500kb
    if (!isLt5M) {
      proxy.$modal.msgWarning("上传文件大小超过限制!" + file.size);
      upLoading.value = 0;
      return false;
    }
    //如果文件类型不在允许上传的范围内
    if (fileType.includes(FileExt)) {
      return true;
    } else {
      proxy.$modal.msgWarning("上传文件格式不正确!");
      upLoading.value = 0;
      return false;
    }
  }
};
const uploadHttpRequestAdd1 = (data) => {
  upload1.value.clearFiles();
  const formData = new FormData();
  formData.append("file", data.file);
  fileupload(formData).then((res) => {
    let value =
      modeHttps == "development"
        ? "/dev-api"
        : modeHttps == "production"
        ? "/prod-api"
        : "/stage-api";
    state.formData.address = previewHttps + value + res.fileName;
    state.formData.originalFilename = res.originalFilename;
    state.fileList1 = [];
    state.fileList1.push({
      name: res.originalFilename,
      url: state.formData.address,
    });
    proxy.$modal.msgSuccess(res.msg);
  });
};
const beforeUpload1 = (file) => {
  //上传前的钩子
  if (file.type != "" || file.type != null || file.type != undefined) {
    //截取文件的后缀，判断文件类型
    const FileExt = file.name.replace(/.+\./, "").toLowerCase();
    // 计算文件的大小
    const isLt5M = file.size / 1024 < 500; //这里做文件大小限制
    //如果大于500kb
    if (!isLt5M) {
      proxy.$modal.msgWarning("上传文件大小超过限制!");
      upLoading.value = 0;
      return false;
    }
    //如果文件类型不在允许上传的范围内
    if (fileType.includes(FileExt)) {
      return true;
    } else {
      proxy.$modal.msgWarning("上传文件格式不正确!");
      upLoading.value = 0;
      return false;
    }
  }
};
const uploadHttpRequestAdd2 = (data) => {
  upload2.value.clearFiles();
  const formData = new FormData();
  formData.append("file", data.file);
  fileupload(formData).then((res) => {
    let value =
      modeHttps == "development"
        ? "/dev-api"
        : modeHttps == "production"
        ? "/prod-api"
        : "/stage-api";
    state.formData.address = previewHttps + value + res.fileName;
    state.fileList2.push({
      name: res.originalFilename,
      url: state.formData.address,
    });
    proxy.$modal.msgSuccess(res.msg);
  });
};
const beforeUpload2 = (file) => {
  //上传前的钩子
  if (file.type != "" || file.type != null || file.type != undefined) {
    //截取文件的后缀，判断文件类型
    const FileExt = file.name.replace(/.+\./, "").toLowerCase();
    // 计算文件的大小
    const isLt5M = file.size / 1024 < 500; //这里做文件大小限制
    //如果大于500kb
    if (!isLt5M) {
      proxy.$modal.msgWarning("上传文件大小超过限制!");
      upLoading.value = 0;
      return false;
    }
    //如果文件类型不在允许上传的范围内
    if (fileType.includes(FileExt)) {
      return true;
    } else {
      proxy.$modal.msgWarning("上传文件格式不正确!");
      upLoading.value = 0;
      return false;
    }
  }
};
const uploadHttpRequestAdd3 = (data) => {
  upload2.value.clearFiles();
  const formData = new FormData();
  formData.append("file", data.file);
  fileupload(formData).then((res) => {
    state.formData.imagePath = previewHttps + res.fileName;
    state.fileList3.push({
      name: res.originalFilename,
      url: state.formData.imagePath,
    });
    proxy.$modal.msgSuccess(res.msg);
  });
};
const beforeUpload3 = (file) => {
  //上传前的钩子
  if (file.type != "" || file.type != null || file.type != undefined) {
    //截取文件的后缀，判断文件类型
    const FileExt = file.name.replace(/.+\./, "").toLowerCase();
    // 计算文件的大小
    const isLt5M = file.size / 1024 < 500; //这里做文件大小限制
    //如果大于500kb
    if (!isLt5M) {
      proxy.$modal.msgWarning("上传文件大小超过限制!");
      upLoading.value = 0;
      return false;
    }
    //如果文件类型不在允许上传的范围内
    if (fileType.includes(FileExt)) {
      return true;
    } else {
      proxy.$modal.msgWarning("上传文件格式不正确!");
      upLoading.value = 0;
      return false;
    }
  }
};

function handlePictureCardPreview(uploadFile) {
  state.dialogVisiblepictureCardPreview = true;
  state.dialogImageUrl = uploadFile.url;
}

function alarmTypeChange(val) {
  if (val == 0) {
    state.nowranDis = true;
    state.noshangwranDis = true;
  } else if (val == 1) {
    state.nowranDis = false;
    state.noshangwranDis = true;
  } else {
    state.nowranDis = false;
    state.noshangwranDis = false;
  }
}
// 高电平输入事件
function highShowBlur(val) {
  state.normalLogicList[1].name = state.formData.highShow;
}

function lowShowBlur(val) {
  state.normalLogicList[0].name = state.formData.lowShow;
}
// 多参信息树形
function nodeclick(data, node) {
  state.nodeclickList = data;
  // delete state.nodeclickList.label
  // delete state.nodeclickList.value
}

function nodeclickchange() {
  if (!state.formData.sensorList) {
    state.formData.sensorList = [];
  }
  state.formData.sensorList.push(state.nodeclickList);
  state.formData.sensorList = Array.from(new Set(state.formData.sensorList));
  state.formData.sensorIdList = state.formData.sensorList.map((item) => {
    return item.sensorId;
  });
}

function sensorListdelClick(row) {
  state.formData.sensorList.splice(row, 1);
  state.formData.sensorIdList = state.formData.sensorList.map((item) => {
    return item.sensorId;
  });
}

console.log(route.query);
function rowStyle({ row, rowIndex }) {
  if (rowIndex % 2 !== 0) {
    return { "background-color": "#f0f3f9" };
  } else {
    return { "background-color": "" };
  }
}
if (route.query.primaryIndexId) {
  if (route.query.tabName == "simulate") {
    state.tabNameData = "模拟量传感器";
    state.tabName = "simulate";
    state.optionsList = state.options;
  }
  if (route.query.tabName == "switch") {
    state.tabNameData = "开关量传感器";
    state.tabName = "switch";
    state.optionsList = state.options1;
  }
  if (route.query.tabName == "add") {
    state.tabNameData = "累计量传感器";
    state.tabName = "add";
    state.optionsList = state.options2;
  }
  if (route.query.tabName == "multiple") {
    state.tabNameData = "多参传感器";
    state.tabName = "multiple";
    state.optionsList = state.options3;
  }
}
</script>
<style scoped lang="scss">
.inputrange {
  background: rgba(91, 109, 128, 0.08);

  ::v-deep .el-input__wrapper {
    box-shadow: none;
    background: rgba(91, 109, 128, 0);
  }
}
</style>